clear all 
set more off

********************************************************************************
***** Project: The Short and Long Term Effects of In-Person Performance Feedback
********************************************************************************
***** A. R. Soetevent & G. J. Romensen
********************************************************************************
***  Eco Coach Survey Data * Analysis
********************************************************************************

*global filepath "C:\JPEMicReplication"
*global paperpath "$filepath\TablesGraphs"

use "$filepath\DEPO\SurveyDataDEPO.dta"
log using "$filepath/Logs/X09AnalysisSurvey.log", replace


bysort functiegroep: gen Nfunctiegroep=_N
bysort concessiegebied: gen Nconcessiegebied=_N
bysort fuel_meestevooruitgang: gen Nfuelvooruitgang=_N
bysort fuel_minstevooruitgang: gen Nfuelminstevooruitgang=_N
bysort fuel_herhalingsessie: gen Nfuelherhalingsessie=_N
bysort ABC_meestevooruitgang: gen NABC_meestevooruitgang=_N
bysort ABC_minstevooruitgang: gen NABC_minstevooruitgang=_N
bysort ABC_blijvend: gen NABC_blijvend=_N

* Comparison ECO coaches vs. teammanagers
* Lasting impact?
gen comparisons=.
replace comparisons=0 if functiegroep=="ECO coach en/of buschauffeur"
replace comparisons=1 if functiegroep=="Teammanager"

*******************************************
**** Analysis ***
*******************************************
* 1. Who filled out the survey? 
* 2. Fuel 
* 3. ABC
* 4. Offer coaching under which conditions?

* 1. Who filled out the survey? 
/*graph pie Nfunctiegroep, over(functiegroep) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) ///
name(pie_functies, replace)

graph display pie_functies
graph save "$filepath\TablesGraphs\pie_functies.png", replace
graph export "$filepath\TablesGraphs\pie_functies.png", replace

graph pie Nconcessiegebied, over(concessiegebied) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) ///
name(pie_concessies, replace)

graph display pie_concessies
graph save "$filepath\TablesGraphs\pie_concessies.png", replace
graph export "$filepath\TablesGraphs\pie_concessies.png", replace
*/

/*** 2. Fuel ***/
** Estimate fuel_extrameters by functiegroep
tabstat fuel_extrameters if functiegroep!="Overig", by(functiegroep) s(min mean median max n)
tabstat fuel_extrameters if functiegroep!="Overig" & area!="FR", by(functiegroep) s(min mean median max n)
tabstat fuel_extrameters if functiegroep!="Overig" & area=="OTHER", by(functiegroep) s(min mean median max n)
tabstat fuel_extrameters if functiegroep!="Overig", by(area) s(min mean median max n)

tabulate functiegroep, generate(fg)
reg fuel_extrameters fg3 fg4
reg fuel_extrameters fg3 fg4 if  area!="FR"
reg fuel_extrameters fg3 fg4 if  area=="OTHER"

* MWW test
ranksum fuel_extrameters if (comparisons==0 | comparisons==1), by(comparisons)
sum fuel_extrameters
local fuelmean=r(mean)

*hist fuel_extrameters, width(100) kdensity freq bcolor(%70) xline(`fuelmean') ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) ///
ytitle(Frequentie) xtitle(Extra meters per liter brandstof na een coachingsessie) ///
name(hist_fuelmeters, replace)

*graph display hist_fuelmeters
*graph save "$paperpath\hist_fuelmeters.png", replace
*graph export "$paperpath\hist_fuelmeters.png", replace

* How many respondents believe this effect to be negative?
count if fuel_extrameters<0
di 100*(6/85)

sum fuel_extrameters if comparisons==0
local fuelmeancoach=r(mean)
sum fuel_extrameters if comparisons==1
local fuelmeanmanager=r(mean)

tabstat fuel_extrameters, stat(mean sd n) by(comparison)
tabstat A_percabrupt, stat(mean sd n) by(comparison)
tabstat B_percabrupt, stat(mean sd n) by(comparison)
tabstat C_percabrupt, stat(mean sd n) by(comparison)

bysort comparisons: count if A_percabrupt<0
bysort comparisons: count if B_percabrupt<0
bysort comparisons: count if C_percabrupt<0

********************************************************************************************************************************
***  Figure M.13: Expectations of Coaches and Managers: How Many Extra Meters per Liter of Fuel Right After a Coaching Session?
********************************************************************************************************************************
twoway (kdensity fuel_extrameters if comparisons==0, xline(`fuelmeancoach', lcolor(red))  width(100) color(green%50)) ///        
       (kdensity fuel_extrameters if comparisons==1, xline(`fuelmeanmanager', lcolor(blue)) width(100) color(black%50)), ///   
       legend(order(1 "ECO coach" 2 "Teammanager" )) ytitle(Density) xtitle(Expected extra meters per liter fuel after coaching) ///
	   graphregion(fcolor(white) lcolor(white)) bgcolor(white) ///
	   name(fuelmeterscomparison, replace)

graph display fuelmeterscomparison
graph save "$paperpath\fuelmeterscomparison.png", replace
graph export "$paperpath\fuelmeterscomparison.png", replace 

************************************************************************************************************************
***  Table M.14: Responses to the Survey Question: Will Coaching Have a Lasting Effect on Fuel Consumption?
************************************************************************************************************************
local uitkomst "fuel A B C"
foreach var of local uitkomst {
gen byte 	`var'_lasting = .
replace 	`var'_lasting = 1 if `var'_blijvend == "Ja"
replace 	`var'_lasting = 0 if `var'_blijvend == "Nee"
tab `var'_lasting
tab `var'_lasting functiegroep
tabstat `var'_lasting if functiegroep!="Overig", by(functiegroep) s(mean n)

** Difference ECO coach and Team manager?
reg  `var'_lasting comparisons if comparisons==0|comparisons==1

tab `var'_half
sum `var'_half, detail
* fuel: on average 6.5 weeks; median: 4
tabstat `var'_half, by(functiegroep) s(mean n)
}

local ABC "A B C"

foreach var of local ABC {
sum `var'_percabrupt
local `var'_mean=r(mean)

*hist `var'_percabrupt, kdensity freq bcolor(%70) xline(``var'_mean') ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) ///
ytitle(Frequency) xtitle(Percentage reduction in events) ///
name(hist_`var'perc, replace)

*graph display hist_`var'perc
*graph save "$paperpath\hist_`var'perc.png", replace
* graph export "$paperpath\hist_`var'perc.png", replace
}


******************************************************************************************************
** Within-person differences in whether effect different outcomes is lasting?
******************************************************************************************************
preserve 
expand 4,  generate(dupi)
replace dupi = 2 if dupi == 1 & responseID == responseID[_n+1] & responseID == responseID[_n+2]
replace dupi = 3 if dupi[_n-1] == 2
replace dupi = 4 if dupi[_n-1] == 3

gen lasting = 0
replace lasting = fuel_lasting if dupi==0
replace lasting = A_lasting if dupi==2
replace lasting = B_lasting if dupi==3
replace lasting = C_lasting if dupi==4

gen halfing = 0
replace halfing = fuel_half if dupi==0
replace halfing = A_half if dupi==2
replace halfing = B_half if dupi==3
replace halfing = C_half if dupi==4


egen ID = group(responseID)
reg lasting i.dupi
xtset ID
* differential assessment lasting?
areg lasting i.dupi, absorb(ID) vce(cl ID)
* ANS: Yes
bysort functiegroep: areg lasting i.dupi, absorb(ID) vce(cl ID)

* differential assessment halfing?
areg halfing i.dupi, absorb(ID) vce(cl ID)
* ANS: No
restore

******************************************************************************************************
* Among which groups of drivers most effect is expected?

*** Fuel

tab fuel_meestevooruitgang
tab ABC_meestevooruitgang functiegroep
*graph bar (percent) Nfuelvooruitgang,   scheme(s1mono) over(v2fuel_meestevooruitgang, relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" /// 
4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) ///
name(bar_fuelmeestevooruitgang, replace)

*graph display bar_fuelmeestevooruitgang
*graph save "$paperpath\bar_fuelmeestevooruitgang.png", replace
*graph export "$paperpath\bar_fuelmeestevooruitgang.png", replace 

bysort fuel_meestevooruitgang comparisons: gen compNfuelvooruitgang=_N

gen coachNfuelvooruitgang=compNfuelvooruitgang if comparisons==0
gen managerNfuelvooruitgang=compNfuelvooruitgang if comparisons==1

*graph bar (percent) coachNfuelvooruitgang managerNfuelvooruitgang,  scheme(s1mono) over(v2fuel_meestevooruitgang, relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" /// 
4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) ///
legend(label(1 "ECO coaches") label(2 "Teammanagers")) ///
name(bar_fuelmeestevooruitgangcomp, replace)

*graph display bar_fuelmeestevooruitgangcomp
*graph save "$paperpath\bar_fuelmeestevooruitgangcomp.png", replace
*graph export "$paperpath\bar_fuelmeestevooruitgangcomp.png", replace 

*** ABC

tab ABC_meestevooruitgang
tab ABC_meestevooruitgang functiegroep

*graph bar (percent) NABC_meestevooruitgang,   scheme(s1mono) over(v2ABC_meestevooruitgang, relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" /// 
4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) bar(1, fcolor(olive_teal)) ///
name(bar_ABC_meestevooruitgang, replace)

*graph display bar_ABC_meestevooruitgang
*graph save "$paperpath\bar_ABC_meestevooruitgang.png", replace
*graph export "$paperpath\bar_ABC_meestevooruitgang.png", replace


bysort ABC_meestevooruitgang comparisons: gen compNABCvooruitgang=_N

gen coachNABCvooruitgang=compNABCvooruitgang if comparisons==0
gen managerNABCvooruitgang=compNABCvooruitgang if comparisons==1

*graph bar (percent) coachNABCvooruitgang managerNABCvooruitgang,  scheme(s1mono) over(v2ABC_meestevooruitgang, relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" /// 
4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) ///
legend(label(1 "ECO coaches") label(2 "Teammanagers")) ///
name(bar_ABCmeestevooruitgangcomp, replace)

*graph display bar_ABCmeestevooruitgangcomp
*graph save "$paperpath\bar_ABCmeestevooruitgangcomp.png", replace
*graph export "$paperpath\bar_ABCmeestevooruitgangcomp.png", replace 


******************************************************************************************************
* Among which groups of drivers least of effect is expected?

** Fuel
tab fuel_minstevooruitgang

*graph bar Nfuelminstevooruitgang,   scheme(s1mono) over(v2fuel_minstevooruitgang, relabel(1 "Geen idee" 2 "Geen verschil" 3 "Onderste 25%" /// 
4 "Onderste 25%-50%" 5 "Beste 25%-50%" 6 "Beste 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) ///
name(bar_fuelminstevooruitgang, replace)

*graph display bar_fuelminstevooruitgang
*graph save "$paperpath\bar_fuelminstevooruitgang.png", replace
*graph export "$paperpath\bar_fuelminstevooruitgang.png", replace 

bysort fuel_minstevooruitgang comparisons: gen compNfuelminstevooruitgang=_N
gen coachNfuelminstevooruitgang=compNfuelminstevooruitgang if comparisons==0
gen managerNfuelminstevooruitgang=compNfuelminstevooruitgang if comparisons==1

*graph bar (percent) coachNfuelminstevooruitgang managerNfuelminstevooruitgang, scheme(s1mono) over(v2fuel_minstevooruitgang, relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" /// 
4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) ///
legend(label(1 "ECO coaches") label(2 "Teammanagers")) ///
name(bar_fuelminstvooruitgangcomp, replace)

*graph display bar_fuelminstvooruitgangcomp
*graph save "$paperpath\bar_fuelminstvooruitgangcomp.png", replace
*graph export "$paperpath\bar_fuelminstvooruitgangcomp.png", replace 

** ABC

tab ABC_minstevooruitgang
*graph bar (percent) NABC_minstevooruitgang,   scheme(s1mono) over(v2ABC_minstevooruitgang, relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" /// 
4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) bar(1, fcolor(olive_teal)) ///
name(bar_ABC_minstevooruitgang, replace)

*graph display bar_ABC_minstevooruitgang
*graph save "$paperpath\bar_ABC_minstevooruitgang.png", replace
*graph export "$paperpath\bar_ABC_minstevooruitgang.png", replace

bysort ABC_minstevooruitgang comparisons: gen compNABCminstevooruitgang=_N
gen coachNABCminstevooruitgang=compNABCminstevooruitgang if comparisons==0
gen managerNABCminstevooruitgang=compNABCminstevooruitgang if comparisons==1

*graph bar (percent) coachNABCminstevooruitgang managerNABCminstevooruitgang, scheme(s1mono) over(v2ABC_minstevooruitgang, relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" /// 
4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ytitle(Percentage) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000) ///
legend(label(1 "ECO coaches") label(2 "Teammanagers")) ///
name(bar_ABCminstvooruitgangcomp, replace)

*graph display bar_ABCminstvooruitgangcomp
*graph save "$paperpath\bar_ABCminstvooruitgangcomp.png", replace
*graph export "$paperpath\bar_ABCminstvooruitgangcomp.png", replace 


*** Do the expectations of ECO coaches and team managers differ by outcome variable?

** Lowest effect
preserve
expand 4,  generate(dupi)
replace dupi = 2 if dupi == 1 & responseID == responseID[_n+1] & responseID == responseID[_n+2]
replace dupi = 3 if dupi[_n-1] == 2
replace dupi = 4 if dupi[_n-1] == 3
replace dupi = 1 if dupi == 0

tab dupi

gen uitkomst="Fuel" if dupi == 1 | dupi == 2
replace uitkomst="ABC" if dupi == 3 | dupi == 4
gen groep="ECO coach" if dupi == 1 | dupi == 3
replace groep="Manager" if dupi == 2 | dupi == 4

gen minstevooruitgang = v2fuel_minstevooruitgang if  uitkomst == "Fuel" & groep == "ECO coach"  & comparisons == 0
replace minstevooruitgang = v2ABC_minstevooruitgang if  uitkomst == "ABC" & groep == "ECO coach"  & comparisons == 0
replace minstevooruitgang = v2fuel_minstevooruitgang if  uitkomst == "Fuel" & groep == "Manager" & comparisons == 1
replace minstevooruitgang = v2ABC_minstevooruitgang if  uitkomst == "ABC" & groep == "Manager" & comparisons == 1

catplot uitkomst groep minstevooruitgang, ///
percent(uitkomst groep) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small))) ///
var3opts(label(labsize(small)) relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" 4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ///
recast(bar) ///
ylabel(,labsize(small)) ///
legend(size(small)) ///
ytitle("Percent of respondents", size(small)) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000)  asyvar scheme(s1mono) ///
name(bar_minstvooruitABCvsFuel, replace)

graph display bar_minstvooruitABCvsFuel
graph save "$paperpath\bar_minstvooruitABCvsFuel.png", replace
graph export "$paperpath\bar_minstvooruitABCvsFuel.png", replace 


** Stat. sign. differences?
tabulate minstevooruitgang, generate(vooruit)

forv runner = 1/6 {
    di "ECO Coach - Uitkomst: `runner'"
ttest vooruit`runner' if comparisons == 0, by(uitkomst)
}
forv runner = 1/6 {
    di "Manager - Uitkomst: `runner'"
ttest vooruit`runner' if comparisons == 1, by(uitkomst)
}

	catplot groep uitkomst minstevooruitgang, ///
	percent(groep uitkomst) ///
	var1opts(label(labsize(small))) ///
	var2opts(label(labsize(small))) ///
	var3opts(label(labsize(small)) relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" 4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ///
	recast(bar) ///
	ylabel(,labsize(small)) ///
	legend(size(small)) ///
	ytitle("Percent of respondents", size(small)) ///
	graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000)  asyvar scheme(s1mono) ///
name(bar_minstvooruitCoachvsMan, replace)

graph display bar_minstvooruitCoachvsMan
graph save "$paperpath\bar_minstvooruitCoachvsMan.png", replace
graph export "$paperpath\bar_minstvooruitCoachvsMan.png", replace 

	** Stat. sign. differences?
	forv runner = 1/6 {
		di "Minst. vooruit Fuel Coach - Uitkomst: `runner'"
	ttest vooruit`runner' if uitkomst == "Fuel", by(comparisons)
	}
	forv runner = 1/6 {
		di "Minst. vooruit ABC - Uitkomst: `runner'"
	ttest vooruit`runner' if uitkomst == "ABC", by(comparisons)
	}

	catplot minstevooruitgang groep uitkomst if minstevooruitgang>2, ///
	percent(groep uitkomst) ///
	var1opts(label(labsize(small)) relabel(1 "Bottom 25%" 2 "Bottom 25%-50%" 3 "Top 25%-50%" 4 "Top 25%")) ///
	var2opts(label(labsize(small))) ///
	var3opts(label(labsize(small))) ///
		recast(bar) ///
	ylabel(,labsize(small)) ///
	legend(size(small)) ///
	ytitle("Percent of respondents", size(small)) ///
	graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000)  asyvar scheme(s1mono) ///
	name(bar_minstvooruitBotvsTop, replace)

graph display bar_minstvooruitBotvsTop
graph save "$paperpath\bar_minstvooruitBotvsTop.png", replace
graph export "$paperpath\bar_minstvooruitBotvsTop.png", replace 



	** Stat. sign. differences?
	forv runner = 3/5 {
		di "Bot vs. Top Fuel Coach"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "ECO coach"  & uitkomst == "Fuel"
	}
	forv runner = 3/5 {
		di "Bot vs. Top Fuel Manager"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "Manager"  & uitkomst == "Fuel"
	}
	forv runner = 3/5 {
		di "Bot vs. Top ABC Coach"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "ECO coach"  & uitkomst == "ABC"
	}
	forv runner = 3/5 {
		di "Bot vs. Top ABC Manager"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "Manager"  & uitkomst == "ABC"
	}

restore 

*******************************************************************************************************************
** Figure M.14: Expectations of Coaches and Managers: Which Group of Drivers Will Benefit the Most from Coaching?
*******************************************************************************************************************
preserve
expand 4,  generate(dupi)
replace dupi = 2 if dupi == 1 & responseID == responseID[_n+1] & responseID == responseID[_n+2]
replace dupi = 3 if dupi[_n-1] == 2
replace dupi = 4 if dupi[_n-1] == 3
replace dupi = 1 if dupi == 0

tab dupi

gen uitkomst="Fuel" if dupi == 1 | dupi == 2
replace uitkomst="ABC" if dupi == 3 | dupi == 4
gen groep="ECO coach" if dupi == 1 | dupi == 3
replace groep="Manager" if dupi == 2 | dupi == 4

gen meestevooruitgang = v2fuel_meestevooruitgang if  uitkomst == "Fuel" & groep == "ECO coach"  & comparisons == 0
replace meestevooruitgang = v2ABC_meestevooruitgang if  uitkomst == "ABC" & groep == "ECO coach"  & comparisons == 0
replace meestevooruitgang = v2fuel_meestevooruitgang if  uitkomst == "Fuel" & groep == "Manager" & comparisons == 1
replace meestevooruitgang = v2ABC_meestevooruitgang if  uitkomst == "ABC" & groep == "Manager" & comparisons == 1

catplot uitkomst groep meestevooruitgang, ///
percent(uitkomst groep) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small))) ///
var3opts(label(labsize(small)) relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" 4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ///
recast(bar) ///
ylabel(,labsize(small)) ///
legend(size(small)) ///
ytitle("Percent of respondents", size(small)) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000)  asyvar scheme(s1mono) ///
name(bar_meestvooruitABCvsFuel, replace)

graph display bar_meestvooruitABCvsFuel
graph save "$paperpath\bar_meestvooruitABCvsFuel.png", replace
graph export "$paperpath\bar_meestvooruitABCvsFuel.png", replace 

** Stat. sign. differences?
tabulate meestevooruitgang, generate(vooruit)

forv runner = 1/6 {
    di "Meest ABC vs Fuel ECO Coach - Uitkomst: `runner'"
ttest vooruit`runner' if comparisons == 0, by(uitkomst)
}
forv runner = 1/6 {
    di "Meest ABC vs Fuel Manager - Uitkomst: `runner'"
ttest vooruit`runner' if comparisons == 1, by(uitkomst)
}

	catplot groep uitkomst meestevooruitgang, ///
	percent(groep uitkomst) ///
	var1opts(label(labsize(small))) ///
	var2opts(label(labsize(small))) ///
	var3opts(label(labsize(small)) relabel(1 "No idea" 2 "No difference" 3 "Bottom 25%" 4 "Bottom 25%-50%" 5 "Top 25%-50%" 6 "Top 25%")) ///
	recast(bar) ///
	ylabel(,labsize(small)) ///
	legend(size(small)) ///
	ytitle("Percent of respondents", size(small)) ///
	graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000)  asyvar scheme(s1mono) ///
	name(bar_meestvooruitCoachvsMan, replace)

graph display bar_meestvooruitCoachvsMan
graph save "$paperpath\bar_meestvooruitCoachvsMan.png", replace
graph export "$paperpath\bar_meestvooruitCoachvsMan.png", replace

	** Stat. sign. differences?
	forv runner = 1/6 {
		di "Meest Fuel Coach - Uitkomst: `runner'"
	ttest vooruit`runner' if uitkomst == "Fuel", by(comparisons)
	}
	forv runner = 1/6 {
		di "Meest ABC - Uitkomst: `runner'"
	ttest vooruit`runner' if uitkomst == "ABC", by(comparisons)
	}

	catplot meestevooruitgang groep uitkomst if meestevooruitgang>2, ///
	percent(groep uitkomst) ///
	var1opts(label(labsize(small)) relabel(1 "Bottom 25%" 2 "Bottom 25%-50%" 3 "Top 25%-50%" 4 "Top 25%")) ///
	var2opts(label(labsize(small))) ///
	var3opts(label(labsize(small))) ///
		recast(bar) ///
	ylabel(,labsize(small)) ///
	legend(size(small)) ///
	ytitle("Percent of respondents", size(small)) ///
	graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000)  asyvar scheme(s1mono) ///
	name(bar_meestvooruitBotvsTop, replace)

graph display bar_meestvooruitBotvsTop
graph save "$paperpath\bar_meestvooruitBotvsTop.png", replace
graph export "$paperpath\bar_meestvooruitBotvsTop.png", replace

	** Stat. sign. differences?
	forv runner = 3/5 {
		di "Fuel Coach"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "ECO coach"  & uitkomst == "Fuel"
	}
	forv runner = 3/5 {
		di "Fuel Manager"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "Manager"  & uitkomst == "Fuel"
	}
	forv runner = 3/5 {
		di "ABC Coach"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "ECO coach"  & uitkomst == "ABC"
	}
	forv runner = 3/5 {
		di "ABC Manager"
		local runnerplus = `runner'+1 
	ttest vooruit`runner'== vooruit`runnerplus' if groep == "Manager"  & uitkomst == "ABC"
	}

restore 

******************************************************************************************************
* Per quantile: net "most improvement" vs. "least improvement"
forv runner = 1/4 {
		local hulp = `runner' + 2
	gen byte fuelnettoBottom`runner' =  1  if v2fuel_meestevooruitgang==`hulp' & v2fuel_minstevooruitgang!=`hulp'
	replace  fuelnettoBottom`runner' =  0  if v2fuel_meestevooruitgang==`hulp' & v2fuel_minstevooruitgang==`hulp'
	replace  fuelnettoBottom`runner' =  0  if v2fuel_meestevooruitgang!=`hulp' & v2fuel_minstevooruitgang!=`hulp'
	replace  fuelnettoBottom`runner' =  -1 if v2fuel_meestevooruitgang!=`hulp' & v2fuel_minstevooruitgang==`hulp'
	
	gen  ABCnettoBottom`runner' =  1  if v2ABC_meestevooruitgang==`hulp' & v2ABC_minstevooruitgang!=`hulp'
	replace  ABCnettoBottom`runner' =  0  if v2ABC_meestevooruitgang==`hulp' & v2ABC_minstevooruitgang==`hulp'
	replace  ABCnettoBottom`runner' =  0  if v2ABC_meestevooruitgang!=`hulp' & v2ABC_minstevooruitgang!=`hulp'
	replace  ABCnettoBottom`runner' =  -1 if v2ABC_meestevooruitgang!=`hulp' & v2ABC_minstevooruitgang==`hulp'
}
	
	tabstat fuelnettoBottom* if functiegroep == "ECO coach en/of buschauffeur" | functiegroep == "Teammanager", s(mean N) by(functiegroep)
	tabstat ABCnettoBottom*  if functiegroep == "ECO coach en/of buschauffeur" | functiegroep == "Teammanager", s(mean N) by(functiegroep)

	** Regressions for sign diffferences ECO coach vs Manager
	forv runner = 1/4 {
	reg fuelnettoBottom`runner' comparisons
	reg ABCnettoBottom`runner' comparisons
	}
	
*******************************************************************************************************************
** Figure  M.15: Expectations of Coaches and Managers: Is Repetition Needed For a Lasting Impact?
*******************************************************************************************************************
preserve
expand 4,  generate(dupi)
replace dupi = 2 if dupi == 1 & responseID == responseID[_n+1] & responseID == responseID[_n+2]
replace dupi = 3 if dupi[_n-1] == 2
replace dupi = 4 if dupi[_n-1] == 3
replace dupi = 1 if dupi == 0

tab dupi

gen uitkomst="Fuel" if dupi == 1 | dupi == 2
replace uitkomst="ABC" if dupi == 3 | dupi == 4
gen groep="ECO coach" if dupi == 1 | dupi == 3
replace groep="Manager" if dupi == 2 | dupi == 4

gen meestevooruitgang = v2fuel_herhalingsessie if  uitkomst == "Fuel" & groep == "ECO coach"  & comparisons == 0
replace meestevooruitgang = v2ABC_blijvend if  uitkomst == "ABC" & groep == "ECO coach"  & comparisons == 0
replace meestevooruitgang = v2fuel_herhalingsessie if  uitkomst == "Fuel" & groep == "Manager" & comparisons == 1
replace meestevooruitgang = v2ABC_blijvend if  uitkomst == "ABC" & groep == "Manager" & comparisons == 1

catplot uitkomst groep meestevooruitgang, ///
percent(uitkomst groep) ///
var1opts(label(labsize(small))) ///
var2opts(label(labsize(small))) ///
var3opts(label(labsize(small)) relabel(1 "Yes" 2 "No, 1x is sufficient" 3 "No, effect is minimal"  4 "No, effect is negative")) ///
recast(bar) ///
ylabel(,labsize(small)) ///
legend(size(small)) ///
ytitle("Percent of respondents", size(small)) ///
graphregion(fcolor(white) lcolor(white)) bgcolor(white) xsize(10.000)  asyvar scheme(s1mono) ///
name(bar_lastingABCvsFuel, replace)

graph display bar_lastingABCvsFuel
graph save "$paperpath\bar_lastingABCvsFuel.png", replace
graph export "$paperpath\bar_lastingABCvsFuel.png", replace 

** Stat. sign. differences?
tabulate meestevooruitgang, generate(blijvend)

forv runner = 1/4 {
    di "Lasting ABC vs Fuel ECO Coach - Uitkomst: `runner'"
ttest blijvend`runner' if comparisons == 0, by(uitkomst)
}
forv runner = 1/4 {
    di "Lasting ABC vs Fuel Manager - Uitkomst: `runner'"
ttest blijvend`runner' if comparisons == 1, by(uitkomst)
}

forv runner = 1/4 {
    di "Lasting Coach vs. Manager [Fuel] ECO Coach - Uitkomst: `runner'"
ttest blijvend`runner' if uitkomst == "Fuel", by(comparisons)
}
forv runner = 1/4 {
    di "Lasting Coach vs. Manager [ABC] ECO Coach - Uitkomst: `runner'"
ttest blijvend`runner' if uitkomst == "ABC", by(comparisons)
}

restore


/*** 4. Offer Coaching under which Conditions? ***/
************************************************************************************************************************
*** Table M.15: Responses to the Survey Question:
**	Should Coaching be Offered if the Costs Exceed the Fuel Savings Realized by a Coaching Session?
************************************************************************************************************************
tab coachingaanbieden
gen whencoaching = "Improvements in other dimensions than fuel economy only" if coachingaanbieden == "Ja, coaching moet worden aangeboden, maar alleen als het naast kleine brandstofbesparingen ook leidt tot verbeteringen op andere dimensies (zoals milieuprestaties, passagierscomfort, en personeelsontwikkeling)"
replace whencoaching = "Improvements in fuel economy suffice" if coachingaanbieden == "Ja, coaching moet worden aangeboden, ook als het alleen leidt tot kleine brandstofbesparingen"
replace whencoaching = "Only in case of cost reductions" if coachingaanbieden == "Nee, coaching moet alleen worden aangeboden als het leidt tot lagere netto kosten" 
replace whencoaching = "Other" if coachingaanbieden == "Anders, namelijk:"

log close